package cate.game.farm;

import cate.game.play.proce.play.PlayPO;
import cate.game.role.Role;
import easy.java.dev.note.NoteField;
import org.apache.commons.lang3.StringUtils;

public class PassRecord {
    @NoteField(value = "关卡层数")
    public int floor;

    @NoteField(value = "最快通关玩家")
    public PassRole fast;

    @NoteField(value = "最低战力玩家")
    public PassRole lowest;



    public void initialize() {
        if (fast == null) {
            fast = new PassRole();
        }
        fast.initialize();
        if (lowest == null) {
            lowest = new PassRole();
        }
        lowest.initialize();

    }

    /** 处理记录 */
    public synchronized void handle(Role role, PlayPO playPO, long power) {
        String oldFastUid = fast.record(role, playPO, power);
        String oldLowestUid = lowest.record(role, playPO, power);
        // 判断是否要保存这场最新的录像
        if(StringUtils.isNotBlank(oldFastUid)
                || StringUtils.isNotBlank(oldLowestUid)) {
            role.getGame().facilities.getMongo().play.save(playPO);
        }
        // 判断是否要删除老的录像
        if(StringUtils.isNotBlank(oldFastUid)) {
            role.getGame().facilities.getMongo().play.deleteById(oldFastUid);
        }
        if(StringUtils.isNotBlank(oldLowestUid)){
            role.getGame().facilities.getMongo().play.deleteById(oldLowestUid);
        }
    }
}
